/**
 * 
 */
package core.internal.strategy;

import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * @author cipri
 *
 */
public class FileFilter extends Filter
{
    private ArrayList<String> _tokens;
    public boolean applyFiler(String fileName, String filter)
    {
        _tokens = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(filter, ".");
        while (st.hasMoreTokens()) 
        {
            String token = st.nextToken();
            token.replace("*", "");
            _tokens.add(token);
        }
        switch (_tokens.size())
        {
            case 2:
            {
                if (fileName.startsWith(_tokens.get(0)) && fileName.endsWith(_tokens.get(1)))
                {
                    return true;
                }
                else 
                {
                    return false;
                }
            }
            case 1:
            {
                if (fileName.startsWith(_tokens.get(0)))
                {
                    return true;
                }
                else 
                {
                    return false;
                }
            }
            case 0:
            {
                return true;
            }
        }
        return true;
    }
}
